package com.csd.activity;

import java.util.ArrayList;
import java.util.List;

import com.csd.activity.R;
import com.csd.adapter.PeccancyAdapter;
import com.csd.bean.Car;
import com.csd.bean.Peccancy;
import com.csd.bean.PersonalOrder;

import android.app.ActionBar;
import android.app.Activity;
import android.app.ActionBar.LayoutParams;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;

public class PeccancyActivity extends Activity implements OnClickListener {

	private ListView listView;
	private List<Peccancy> list;
	private PeccancyAdapter adapter;
	private ActionBar actionBar;
	private LinearLayout ll_more;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_peccancy);
		initView();
		initActionBar();
	}

	private void initView() {
		// TODO Auto-generated method stub
		list = new ArrayList<>();
		for (int i = 0; i < 5; i++) {
			Peccancy peccancy = new Peccancy();
			peccancy.setTime("2014.12.01");
			peccancy.setId("1215545");
			Car car = new Car();
			car.setCarBrand("别克凯越");
			car.setPlate("沪A456456");
			peccancy.setCar(car);
			PersonalOrder order = new PersonalOrder();
			order.setOrderId("FSFS_154564");
			peccancy.setOrder(order);
			peccancy.setAddress("沈高速123路段");
			peccancy.setAction("抢占车道");
			peccancy.setFee(546.00);
			peccancy.setState("未付款");
			list.add(peccancy);
		}
		listView = (ListView) findViewById(R.id.peccancy_list);
		adapter = new PeccancyAdapter(list, this);
		listView.setAdapter(adapter);
		ll_more = (LinearLayout) findViewById(R.id.more_peccancy);
		ll_more.setOnClickListener(this);
	}

	private void initActionBar() {
		// TODO Auto-generated method stub
		actionBar = getActionBar();
		actionBar.setDisplayHomeAsUpEnabled(false);
		actionBar.setDisplayShowHomeEnabled(false);
		actionBar.setDisplayShowTitleEnabled(false);
		actionBar.setDisplayShowCustomEnabled(true);

		LayoutInflater inflator = (LayoutInflater) getSystemService(this.LAYOUT_INFLATER_SERVICE);

		View v = inflator.inflate(R.layout.actionbar_main, null);
		TextView title = (TextView) v.findViewById(R.id.title);
		title.setText("我的违章记录");
		ImageView img = (ImageView) v.findViewById(R.id.logo);
		img.setImageDrawable(getResources().getDrawable(R.drawable.u86));
		img.setOnClickListener(this);
		ActionBar.LayoutParams layout = new ActionBar.LayoutParams(
				LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
		actionBar.setCustomView(v, layout);

	}

	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		switch (v.getId()) {
		case R.id.logo:
			finish();
			break;
		case R.id.more_peccancy:
			Intent intent = new Intent(PeccancyActivity.this,
					MoreRecoderActivity.class);
			startActivity(intent);
			break;
		default:
			break;
		}
	}
}
